<template>
  <div class="home">
    <el-table :data="tableData" style="width: 100%">
      <el-table-column type="selection" width="55"></el-table-column>
      <el-table-column type="index" width="50"></el-table-column>
      <el-table-column prop="title" label="标题" width="180"></el-table-column>
      <el-table-column prop="content" label="内容" width="180"></el-table-column>
      <el-table-column prop="create_time" label="创建时间" :formatter='formatterDate'></el-table-column>
      <el-table-column prop="delete_time" label="删除时间"></el-table-column>
    </el-table>
  </div>
</template>

<script>
import {getList} from '@/api/index.js'
// @ is an alias to /src
import HelloWorld from '@/components/HelloWorld.vue'

export default {
  name: 'Home',
  data () {
    return {
      tableData:[],
    }
  },
  components: {
    HelloWorld
  },
  methods: {
    formatterDate(row,column){
      return this.formatDate(new Date(row.create_time),'yyyy-MM-dd');
    },
    getList(){
      getList({}).then((res)=>{
      let {data:{newsList}}=res;
      this.tableData=newsList;
    })
    }
  },
  created () {
    // this.$http.get('http://macio.ncyateng.com/api/news/index',{params:{}})
    // .then((res)=>{  //只能用箭头函数，不能使用普通函数，因为如果普通函数这里this就不一样了
    //   console.log(res);
    //   let {data:{newsList}}=res;
    //   this.tableData=newsList;
    // })
    this.getList();
  }
}
</script>
